#include "Camera.h"
#include "CommonDefine.h"


Camera::Camera(int width, int height)
{
	this->_VisibleArea.left = 0;
	this->_VisibleArea.top = 0;
	this->_VisibleArea.right = width;
	this->_VisibleArea.bottom = height;
	this->_Pos = D3DXVECTOR3(width / 2.0f, height / 2.0f, 0.0f);
	this->_Zoom = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
	this->_ScreenPos = D3DXVECTOR3(width/ 2.0f, height/ 3.0f * 2.0f, 0.0f);
	this->_Rot = 0.0f;
	this->_loopTime = 0.0f;
}

HRESULT Camera::Create(LPDIRECT3DDEVICE9 s_pd3dDevice)
{
	return S_OK;
}

void Camera::TargetTo(const Entity &entity)
{
	this->_Pos = entity.GetPos();
	this->_VisibleArea.left		= (int)(this->_Pos.x - this->_VisibleArea.right / 2);
	this->_VisibleArea.top		= (int)(this->_Pos.y - this->_VisibleArea.top / 2);
}

D3DXMATRIX Camera::CalcMatrix()
{
	D3DXMATRIX mat, pos, scale, rot, screenPos;
	D3DXMatrixIdentity(&mat);
	D3DXMatrixIdentity(&pos);
	D3DXMatrixIdentity(&scale);
	D3DXMatrixIdentity(&rot);
	D3DXMatrixIdentity(&screenPos);
	
	D3DXMatrixTranslation(&pos, -this->_Pos.x, -this->_Pos.y, 0.0f);
	D3DXMatrixScaling(&scale, this->_Zoom.x, this->_Zoom.y, 1.0f);
	D3DXMatrixRotationZ(&rot, this->_Rot);
	D3DXMatrixTranslation(&screenPos, this->_ScreenPos.x, this->_ScreenPos.y, this->_ScreenPos.z);

	D3DXMatrixMultiply(&mat, &pos, &scale);
	D3DXMatrixMultiply(&mat, &mat, &rot);
	D3DXMatrixMultiply(&mat, &mat, &screenPos);

	D3DXMatrixMultiply(&mat, &pos, &screenPos);

	return mat;
}

void Camera::Update()
{
}

void Camera::Draw()
{

}

void Camera::Release()
{
}

Camera::~Camera()
{
}